package com.hebang.stcommunityapp.holders;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hebang.stcommunityapp.R;

import cn.bingoogolapple.refreshlayout.BGARefreshViewHolder;

/**
 * Created by 任晋超on 2017/4/19.
 * 下拉刷新和上拉加载时所需的过渡viewholdrer
 */

public class RefreshViewHolderNew extends BGARefreshViewHolder {
    SimpleDraweeView refresh_footer_img;
    SimpleDraweeView refresh_top_img;
//    String txtdata = "正在加载";
    TextView tv_loadingtext;
    TextView tv_loadingmoretext;
    boolean isRefreshEnabled;
    boolean isLoadingMoreEnabled=true;
    /**
     * @param context
     * @param isLoadingMoreEnabled 上拉加载更多是否可用
     */
    public RefreshViewHolderNew(Context context, boolean isLoadingMoreEnabled, boolean isRefreshEnabled) {
        super(context, isLoadingMoreEnabled);
        this.isLoadingMoreEnabled=isLoadingMoreEnabled;
        this.isRefreshEnabled=isRefreshEnabled;

    }
    public RefreshViewHolderNew(Context context, boolean isLoadingMoreEnabled) {
        super(context, isLoadingMoreEnabled);
        this.isLoadingMoreEnabled=isLoadingMoreEnabled;
    }

    @Override
    public View getRefreshHeaderView() {
        this.mRefreshHeaderView = View.inflate(mContext, R.layout.refresh_top, null);
        refresh_top_img = (SimpleDraweeView) mRefreshHeaderView.findViewById(R.id.refresh_top_img);
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_top_img.setController(controller);
//        refresh_top_img.setImageURI(uri);

        tv_loadingtext = (TextView)mRefreshHeaderView.findViewById(R.id.tv_loadingtext);
        tv_loadingtext.setText("正在刷新...");
//        if(!isRefreshEnabled){
//            return null;
//        }
        return mRefreshHeaderView;
    }

    @Override
    public void handleScale(float scale, int moveYDistance) {

    }

    @Override
    public void changeToIdle() {

    }

    @Override
    public void changeToPullDown() {

    }

    @Override
    public void changeToLoadingMore() {
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_footer_img.setController(controller);
//        refresh_footer_img.setImageURI(uri);
        super.changeToLoadingMore();

    }

    @Override
    public void onEndLoadingMore() {
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_footer_img.setController(controller);
//        refresh_footer_img.setImageURI(uri);
        super.onEndLoadingMore();

    }

    @Override
    public void changeToReleaseRefresh() {

    }

    @Override
    public void changeToRefreshing() {
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_top_img.setController(controller);
//        refresh_top_img.setImageURI(uri);
        tv_loadingtext.setText("正在刷新...");
    }

    @Override
    public void onEndRefreshing() {
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_top_img.setController(controller);
//        refresh_top_img.setImageURI(uri);
    }

//    @Override
//    public void setLoadingMoreText(String loadingMoreText) {
//        txtdata = loadingMoreText;
//    }

    @Override
    public View getLoadMoreFooterView() {
        this.mLoadMoreFooterView = View.inflate(mContext, R.layout.refresh_bottom, null);
        refresh_footer_img = (SimpleDraweeView) mLoadMoreFooterView.findViewById(R.id.refresh_footer_img);
        Uri uri = Uri.parse("res://comq.geren.ren.qyfiscalheadlinessecend/" + R.mipmap.loadinglist);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();
        refresh_footer_img.setController(controller);
//        refresh_footer_img.setImageURI(uri);
        tv_loadingmoretext = (TextView) mLoadMoreFooterView.findViewById(R.id.tv_loadingmoretext);
        tv_loadingmoretext.setText("正在加载...");
//        if(!isLoadingMoreEnabled){
//            return null;
//        }
        return mLoadMoreFooterView;
    }
}
